Completed
Push — master ( 1b4532...54964d )
by Andres
01:14
created

angular.controller(ꞌmain-loopꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
c 4
b 0
f 0
nc 1
dl 0
loc 38
rs 8.8571
nop 11

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 3 1
A ��) 0 6 1
A ��) 0 12 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
'use strict';
2
3
angular
4
  .module('game')
5
  .controller('main-loop', ['$scope',
6
    '$interval',
7
    '$timeout',
8
    'savegame',
9
    'achievement',
10
    'util',
11
    'format',
12
    'reaction',
13
    'data',
14
    'visibility',
15
    'state',
16
    function($scope, $interval, $timeout, savegame, achievement, util, format, reaction, data, visibility, state) {
17
      $scope.data = data;
18
      $scope.achievement = achievement;
19
      $scope.util = util;
20
      $scope.format = format;
21
      $scope.reaction = reaction;
22
      $scope.visibility = visibility;
23
      $scope.state = state;
24
25
      let self = this;
26
      let playerCopy = null;
27
28
      self.update = function() {
29
        // do the update in a copy
30
        playerCopy = angular.copy(state.player);
31
        achievement.checkAchievements(playerCopy);
32
33
        state.update(playerCopy);
34
35
        // and update all at once
36
        state.player = playerCopy;
37
38
        $timeout(self.update, 1);
39
      };
40
41
      function save() {
42
        localStorage.setItem('playerStoredITE', JSON.stringify(state.player));
43
      }
44
45
      self.startup = function() {
46
        savegame.load();
47
        state.loading = false;
48
        $timeout(self.update, 1000);
49
        $interval(save, 10000);
50
      };
51
52
      $timeout(self.startup);
53
    }
54
  ]);
55